package ucl.cs.stockbroker.common;

import java.rmi.RemoteException;
import java.util.Map;

/**
 * StockBroker Information Class.
 * @author  Min Park, Saniul Ahmed, Kamil Olesiejuk
 * @version 1.0
 */

public class StockBrokerAccountInfo implements java.io.Serializable {

	private static final long serialVersionUID = 1;

	/**
	 * Returns the account balance.
	 * 
	 * @return balance : double
	 */
	public double getBalance() {
		return balance;
	}

	/**
	 * Returns the account name.
	 * 
	 * @return name : String - account name 
	 */
	public String getName() {
		return name;
	}

	/**
	 * Returns the account number.
	 * 
	 * @return number : int - account number 
	 */
	public int getNumber() {
		return number;
	}

	/**
	 * Returns the potential account value.
	 * 
	 * @return value : double - account potential value
	 */
	public double getValue() {
		return potentialBalance;
	}

	private final String name;
	private final int number;
	private final double balance;
	private final Map<String, Integer> ownedStock;
	private final double potentialBalance;

	/**
	 * StockAccountInfo object constructor. Creates a new object of StockBrokerAccountInfo,
	 * provided with all the data.
	 * 
	 * @param name : String - account name
	 * @param account_number : int - account number
	 * @param balance : double - account balance
	 * @param ownedStock : Map<String, Integer>
	 * @throws RemoteException - on remote communication errors
	 */
	public StockBrokerAccountInfo(String name, int account_number,
			double balance, double value, Map<String, Integer> ownedStock)
			throws RemoteException {
		this.name = name;
		this.number = account_number;
		this.balance = balance;
		this.ownedStock = ownedStock;
		this.potentialBalance = value;
	}

	/**
	 * Returns a string representation of the owned stock data structure.
	 * 
	 * @return owned stock : String
	 */
	private String ownedStockToString() {
		String str = "";
		str += "\n Owned Stock:\n ";
		for (final String company : this.ownedStock.keySet())
			str += company + ":" + this.ownedStock.get(company) + " shares\n ";
		return str;
	}

	public String toString() {
		return " Account number: " + this.number + "\n Account name: "
				+ this.name + "\n Balance: " + this.balance + "\n Pot.Balance: "
				+ this.potentialBalance + this.ownedStockToString();
	}
}
